﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using GameViewModel;

namespace Kolhoz
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private readonly TheGame _game;

        public MainWindow()
        {
            InitializeComponent();
            _game = new TheGame();
            _game.Options.Persons.Add(new Person("Евлампий", 1) { IsSelected = true });
            _game.Options.Persons.Add(new Person("Сигизмунд", 2) { IsSelected = true });
            _game.Options.Persons.Add(new Person("Ратибор", 3) { IsSelected = true });
            _game.Options.Persons.Add(new Person("Гостомысл", 4) { IsSelected = true });
            _game.Options.Persons.Add(new Person("Афиноген", 5) { IsSelected = true });
            DataContext = _game;
        }

        private void CreateUserBtn_OnClick(object sender, RoutedEventArgs e)
        {
            _game.Options.Persons.Add(new Person(NewPlayerNameTextBox.Text, _game.Options.Persons.Max(p => p.Id) + 1));
        }

        private void StartGame_OnClick(object sender, RoutedEventArgs e)
        {
            _game.Start();
        }

        private void PlayerPlus_OnClick(object sender, RoutedEventArgs e)
        {
            var player = ((Button)sender).Tag as Player;
            if (player == null) return;
            _game.Plus(player);
        }

        private void PlayerMinus_OnClick(object sender, RoutedEventArgs e)
        {
            var player = ((Button)sender).Tag as Player;
            if (player == null) return;
            _game.Minus(player);
        }

        private void PlayerPenalty_OnClick(object sender, RoutedEventArgs e)
        {
            var player = ((Button)sender).Tag as Player;
            if (player == null) return;
            _game.Penalty(player);
        }
    }
}
